package com.xinbochuang.machine.admin.controller.scrap;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xinbochuang.machine.admin.domain.macRoom.Equipment;
import com.xinbochuang.machine.admin.domain.scrap.Scrap;
import com.xinbochuang.machine.admin.service.scrap.IScrapService;
import com.xinbochuang.machine.common.controller.BaseController;
import com.xinbochuang.machine.common.domain.TableDataInfo;
import com.xinbochuang.machine.common.utils.SecurityUtils;
import com.xinbochuang.machine.framework.web.domain.AjaxResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 黄晓鹏
 * @date 2020-10-25
 */
@RestController
@RequestMapping("/scrap")
public class ScrapController extends BaseController {

    @Resource
    private IScrapService scrapService;

    /**
     * 下电设备分页列表
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:equ:list')")
    @GetMapping("/equList")
    public TableDataInfo equList(Equipment equipment) {
        IPage<Equipment> list = scrapService.selectEquList(equipment);
        return getDataTable(list);
    }

    /**
     * 新增利旧/报废
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:add')")
    @PostMapping
    public AjaxResult add(@RequestBody Scrap scrap) {
        return toAjax(scrapService.add(scrap));
    }

    /**
     * 利旧/报废分页列表
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:list')")
    @GetMapping("/list")
    public TableDataInfo list(Scrap scrap) {
        IPage<Scrap> list = scrapService.selectScarpList(scrap);
        return getDataTable(list);
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:check')")
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Scrap scrap) {
        return toAjax(scrapService.changeStatus(scrap));
    }

    /**
     * 根据设备id查询机房/机柜
     */
    @GetMapping("/getPlace")
    public AjaxResult getPlace(String equId) {
        return AjaxResult.data(scrapService.selectPlace(equId));
    }

}

